﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CMS.Data;
using CMS.Service.Repository;

namespace CMSApplication.Areas.Administration.Models
{
    public class CustomerModel
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Phone { get; set; }
        public string Addr { get; set; }
        public int Type { get; set; }
        public bool Active { get; set; }
        public DateTime? CreatedOn { get; set; }

        public string TypeName { get; set; }
        public SelectList SLType { get; set; }

        public void GetDataForSL()
        {
            var customer_type_lst = new List<Customer_Type>() { new Customer_Type() { Id = 0, Name = "- - Chọn - -" } };
            var customer_type_srv = new CustomerTypeRepository();
            customer_type_lst.AddRange(customer_type_srv.List());
            SLType = new SelectList(customer_type_lst, "Id", "Name");
        }

        public static void Mapfrom(Customer entity, ref CustomerModel model)
        {
            model.Id = entity.Id;
            model.Name = entity.Name;
            model.Phone = entity.Phone;
            model.Addr = entity.Addr;
            model.Type = entity.Type;
            model.Active = entity.Active;
            model.CreatedOn = entity.CreatedOn;
        }

        public static void Mapfrom(CustomerModel model, ref Customer entity)
        {
            entity.Id = model.Id;
            entity.Name = model.Name;
            entity.Phone = model.Phone;
            entity.Addr = model.Addr;
            entity.Type = model.Type;
            entity.Active = model.Active;
            entity.CreatedOn = model.CreatedOn;
        }
    }
}
